package view;

import java.util.HashMap;
import java.util.Map;

import view.widget.StatedTabWidget;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

import com.shilehui.www.R;

public class MainMenuTabhostActivity extends TabActivity implements OnTabChangeListener {
	
	private Map<String, StatedTabWidget> tabWidgetBuffer;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tabhost);
		// add tab here
		TabHost tabHost = getTabHost();  // The activity TabHost
		TabSpec tabSpec = null;
		Intent intent = null;
		tabWidgetBuffer = new HashMap<String, StatedTabWidget>();
		
		// main layer tab
		intent = new Intent(this, MainLayerActivity.class);
		tabSpec = tabHost.newTabSpec("mainLayer");
		StatedTabWidget tabWidget = new StatedTabWidget(this, this.getResources().getDrawable(R.drawable.main_layer_icon));
		tabSpec.setIndicator(tabWidget);
		tabSpec.setContent(intent);
		tabHost.addTab(tabSpec);
		
		
		tabHost.setOnTabChangedListener(this);
		
		tabHost.setCurrentTabByTag("mainLayer");
	}

	@Override
	public void onTabChanged(String tag) {
		for(StatedTabWidget widget : tabWidgetBuffer.values()){
			widget.setSelected(false);
		}
		tabWidgetBuffer.get(tag).setSelected(true);
	}
	
}
